package com.shgsh.platform.service;

import com.shgsh.common.repository.CURDRepository;
import com.shgsh.platform.model.AdminUser;
import com.shgsh.common.util.DataTable;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * Created by jessy on 2015/8/9.
 */
@Service
public class AdminUserService {

    Logger log = LoggerFactory.getLogger(AdminUserService.class);

    @Autowired
    CURDRepository curdRepository;

    /**
     * 根据用户名 获取用户密码
     * @param name
     * @return
     */
    public AdminUser get(String name){
        if(!StringUtils.isEmpty(name)){
            log.debug("用户名 " + name + " .");
            ArrayList<byte[]> hgetParams = new ArrayList<>();
            hgetParams.add(DataTable.ADMIN_USER.getBytes());
            hgetParams.add(name.getBytes());
            String result = curdRepository.hget(hgetParams);
            if(StringUtils.isEmpty(result))
                return null;
            AdminUser ad = new AdminUser();
            ad.setName(name);
            ad.setPassword(result);
            return ad;
        }
        return null;
    }
}
